#!/bin/sh
#!/bin/sh
source $HOME/.profile
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8

if [ "$1" == "s" ] ||[ "$1" == "show" ]; then
    #cd build
    #./vtest_mysql --list_content
    exit 0;
fi

proc=mysqld
script_name=`basename "$0"`

if [ "$1" == "h" ]||[ "$1" == "help" ];then
    echo "usage:"
    echo "     $script_name  h/help       print this info"
    echo "     $script_name  k/kill       use kill -9 to end mysqld process"
    echo "     $script_name               start mysqld process with file my*.cnf"
exit 0
fi

if [ "$1" == "k" ]||[ "$1" == "kill" ];then
temp="$HOME/tmp.grep.mysqld"
ps -ef | grep  "$proc" | grep `whoami` | grep -v -E  'java|grep'  | awk '{print $2}' > $temp

i=0
cat $temp | while read line
 do
     ((++i))
     arg=$1

     printf "[%03d] kill %s %s\n"  $i "$line" "$arg"
     kill -9 $arg
 done

 rm $temp
exit 0
fi

cd $HOME/mysql/bin
(
    ./mysqld --defaults-file=$HOME/my0.cnf &
    ./mysqld --defaults-file=$HOME/my1.cnf &
    ./mysqld --defaults-file=$HOME/my2.cnf &
)
